<template>
    <div class="top-box">
        <titleComponent title="本年中标金额300万以上项目统计"></titleComponent>
        <div class="center">
            <div class="center-box" v-for="item, i in list" :key="i">
                <img :src="require(`../../../assets/img/right-icon${i + 1}.png`)" />
                <div>
                    <div class="name">{{ item.name }}<span class="unit">({{ item.unit }})</span></div>
                    <div class="value" @click="goLink(item.type)">{{ item.value }}</div>
                </div>
            </div>
        </div>
        <!-- <div class="pie-box">
            <div class="pie-item-box" @click="goLink('2')">
                <div class="pie-title">投标项目省级支撑占比</div>
                <SemicirclePie :dataList="this.mgr && this.mgr.sjZcPre ? this.getNum(this.mgr.sjZcPre) : 0"
                    :colorArr="['#22e1bf', '#dcf2f8', 'transparent']" />
            </div>
            <div class="pie-item-box" @click="goLink()">
                <div class="pie-title">中标项目省级支撑占比</div>
                <SemicirclePie :dataList="this.mgr && this.mgr.zbProSjPre ? this.getNum(this.mgr.zbProSjPre) : 0" />
            </div>
        </div> -->
    </div>
</template>
<script>
import titleComponent from "./titleComponent";
import SemicirclePie from "./SemicirclePie";
export default {
    components: {
        titleComponent,
        SemicirclePie
    },
    watch: {
        mgr(val, oldVal) {
            if (val !== oldVal) {
                this.list = [
                    { name: "参与投标项目数", unit: "个", value: val && val.tbProCount ? val.tbProCount : 0, color: '#ffab4b', type: '1' },
                    { name: "省级支撑方案数", unit: "个", value: val && val.sjZcFaCount ? val.sjZcFaCount : 0, color: '#1e8aff', type: '2' },
                    { name: "中标项目数", unit: "个", value: val && val.zbProCount ? val.zbProCount : 0, color: '#ff293f', type: '3' },
                    { name: "中标项目金额", unit: "万元", value: this.getNumW(val && val.zbProAmount ? val.zbProAmount : 0), color: '#24e1c0', type: '4' }
                ]
            }
        }
    },
    props: {
        mgr: {
            type: Object,
            default: () => { },
        },
        orgId: {
            type: String,
            default: ''
        },
        yearFilter: {
            type: String,
            default: ''
        },
    },
    data() {
        return {
            list: [
                { name: "参与投标项目数", unit: "个", value: this.mgr && this.mgr.tbProCount ? this.mgr.tbProCount : 0, color: '#ffab4b', type: '1' },
                { name: "省级支撑方案数", unit: "个", value: this.mgr && this.mgr.sjZcFaCount ? this.mgr.sjZcFaCount : 0, color: '#1e8aff', type: '2' },
                { name: "中标项目数", unit: "个", value: this.mgr && this.mgr.zbProCount ? this.mgr.zbProCount : 0, color: '#ff293f', type: '3' },
                { name: "中标项目金额", unit: "万元", value: this.getNumW(this.mgr && this.mgr.zbProAmount ? this.mgr.zbProAmount : 0), color: '#24e1c0', type: '4' }
            ]
        }
    },
    methods: {
        goLink(type) {
            let query =
                type == '1' ? { cityCode: this.orgId == '10008' ? '' : this.orgId, yearFilter: this.yearFilter } :
                    type == '2' ? { zcFlag: 'Y', cityCode: this.orgId == '10008' ? '' : this.orgId, yearFilter: this.yearFilter } :
                        type == '3' ? { zbFlag: 'Y', cityCode: this.orgId == '10008' ? '' : this.orgId, yearFilter: this.yearFilter } :
                            type == '4' ? { zbFlag: 'Y', cityCode: this.orgId == '10008' ? '' : this.orgId, yearFilter: this.yearFilter } :
                                { zcFlag: 'Y', zbFlag: 'Y', cityCode: this.orgId == '10008' ? '' : this.orgId, yearFilter: this.yearFilter }
            this.$router.push({ path: '/mgrThreeTable', query });
        },
        getNum(num) {
            return this.truncateToFixed(num * 100, 2)
        },
        getNumW(num) {
            return this.truncateToFixed(num / 10000, 2)
        },
        truncateToFixed(value, decimals) {
            const integerPart = Math.trunc(value); // 获取整数部分
            const decimalPart = value - integerPart; // 获取小数部分
            const factor = Math.pow(10, decimals);
            const truncatedDecimalPart = decimalPart < 0 ? Math.ceil(decimalPart * factor) / factor : Math.floor(decimalPart * factor) / factor; // 根据正负选择向上或向下截断
            return integerPart + truncatedDecimalPart; // 组合整数部分和小数部分
        }
    }
}
</script>
<style lang="scss" scoped>
.top-box {
    background: #fff;
    width: 100%;
    height: 292px;
    margin-bottom: 16px;
    box-sizing: border-box;
    padding: 16px;
}

.center {
    display: flex;
    flex-wrap: wrap;
    margin-top: 14px;
}

.center-box {
    display: flex;
    margin-top: 36px;
    width: 50%;
    flex-wrap: wrap;
    padding-left: 10px;

    img {
        margin-right: 10px;
        width: 70px;
        height: 70px;
        margin-top: 4px;
        position: relative;
        top: -14px;
    }

    .value {
        font-size: 22px;
        color: #0a1b2e;
        font-weight: bold;
        cursor: pointer;
        line-height: 38px;
    }
}

.name {
    font-size: 16px;
    color: #141f32;
    font-weight: bold;
}

.unit {
    color: #a5a7ac;
    font-size: 14px;
    font-weight: 500;
}

.pie-box {
    display: flex;
    justify-content: space-between;

    .pie-title {
        width: 100%;
        height: 36px;
        line-height: 36px;
        border-bottom: 1px solid #ddeffd;
        font-size: 14px;
        text-align: center;
    }

    .pie-item-box {
        width: calc(50% - 7px);
        background: #f0f7fd;
        border-radius: 7px;
        height: 120px;
        margin-top: 12px;
    }
}
</style>